package com.slipper.system.codeless.service;

import com.slipper.system.codeless.bo.ScriptGroovyBO;
import com.slipper.system.codeless.bo.ScriptGroovyHistoryBO;
import com.slipper.system.codeless.dao.ScriptGroovyHistoryDao;
import com.slipper.core.transaction.ReadTransactional;
import com.slipper.core.transaction.WriteTransactional;
import com.slipper.util.BeanUtil;
import com.slipper.util.Tool;
import com.slipper.util.UUID;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@ReadTransactional
public class ScriptGroovyHistoryService {
    @Resource
    private ScriptGroovyHistoryDao scriptGroovyHistoryDao;
    
    public ScriptGroovyHistoryBO queryBy(String id) {
        return scriptGroovyHistoryDao.queryBy(id);
    }
    
    public List<ScriptGroovyHistoryBO> queryList(ScriptGroovyHistoryBO bo) {
        return scriptGroovyHistoryDao.queryList(bo);
    }

    @WriteTransactional
    public int save(ScriptGroovyBO bo) {
        if (Tool.isBlank(bo.getScript())) return 0;

        ScriptGroovyHistoryBO history = BeanUtil.copy(bo, ScriptGroovyHistoryBO.class);
        history.setId(UUID.getUUID());
        history.setGroovyId(bo.getId());
        history.setCreateTime(System.currentTimeMillis());
        return scriptGroovyHistoryDao.insert(history);
    }
}
